﻿using RepoMovies.Data;
using RepoMovies.Data.Models;
using RepoMovies.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace RepoMovies.Adapters.Data
{
    public class MoviesDataAdapter : IMoviesAdapter 
    {
        /// READ
        public MoviesIndexVm GetAllMovies()
        {
            MoviesIndexVm iVm = new MoviesIndexVm();
            using(MoviesDbContext db = new MoviesDbContext()){
                iVm.Movies = db.Movies.ToList();
            }

            return iVm;
        }
        // CREATE
        public void CreateMovie(CreateMovieVm cVm)
        {
            using (MoviesDbContext db = new MoviesDbContext())
            {
                // create and add
                db.Movies.Add(new Movie() { Title = cVm.Title, IsRewatchable = cVm.IsRewatchable, Description = cVm.Description });
                // save
                db.SaveChanges();
            }


        }

    }
}